package viroyal.com.base.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.List;

import viroyal.com.base.R;
import viroyal.com.base.net.entity.SchoolData;
import viroyal.com.base.net.rsp.GetSchoolListResponseS;

/**
 * @author gaochao
 */
public class SchoolListAdapter extends BaseAdapter {

  private List<SchoolData> data;
  private Context context;

  public SchoolListAdapter(List<SchoolData> data, Context context) {
    this.data = data;
    this.context = context;
  }

  @Override
  public int getCount() {
    return data.size();
  }

  @Override
  public Object getItem(int position) {
    return data.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if(convertView == null){
      viewHolder = new ViewHolder();
      convertView = LayoutInflater.from(context).inflate(R.layout.item_school_list, null, false);
      viewHolder.textView = (TextView) convertView.findViewById(R.id.tv_school_name);
      convertView.setTag(viewHolder);
    }else{
      viewHolder = (ViewHolder) convertView.getTag();
    }
    viewHolder.textView.setText(data.get(position).unit_name);
    return convertView;
  }

  //内部类
  class ViewHolder{
    TextView textView;
  }
}
